<html>
<head><meta charset="utf-8"><title>PR #5935 · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html">PR #5935</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="208862327"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208862327" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208862327">(Sep 02 2020 at 17:53)</a>:</h4>
<p>What would be the proper way to turn a <code>hir::ModPath</code> into an <code>ast::Path</code>? I need to do this for updating the <code>handlers</code> code</p>



<a name="208862530"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208862530" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Florian Diebold <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208862530">(Sep 02 2020 at 17:54)</a>:</h4>
<p>as far as I remember, turning it into a string and turning that into the AST using the <code>make</code> functions</p>



<a name="208882633"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208882633" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208882633">(Sep 02 2020 at 20:26)</a>:</h4>
<p>alright</p>



<a name="208950022"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208950022" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208950022">(Sep 03 2020 at 11:01)</a>:</h4>
<p>So I'm not sure what I'm supposed to do about the failing tests now, as said in <a href="https://github.com/rust-analyzer/rust-analyzer/pull/5935#issuecomment-685986572">https://github.com/rust-analyzer/rust-analyzer/pull/5935#issuecomment-685986572</a> the test suite itself panics due to the change of not using the text edit api i imagine?</p>



<a name="208950122"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208950122" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208950122">(Sep 03 2020 at 11:02)</a>:</h4>
<p>I was going to just take a look at this now :)</p>



<a name="208950267"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208950267" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208950267">(Sep 03 2020 at 11:04)</a>:</h4>
<p>So, the <code>insert_use</code> returns a new <code>SyntaxNode</code>, but there's nothing that actually replaces the old node with the new one</p>



<a name="208950312"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208950312" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208950312">(Sep 03 2020 at 11:04)</a>:</h4>
<p>You need to do something like <code>text_edit_builder.replace(old_node.text_range(), new_node.to_string())</code>. Let me check if this works...</p>



<a name="208950671"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208950671" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208950671">(Sep 03 2020 at 11:08)</a>:</h4>
<p>Oh okay, didn't mean to rush <span aria-label="smile" class="emoji emoji-1f642" role="img" title="smile">:smile:</span></p>



<a name="208951878"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208951878" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208951878">(Sep 03 2020 at 11:21)</a>:</h4>
<p><span class="user-mention" data-user-id="300586">@veykril</span> urgh, the API there are not great.</p>
<p>I've managed to fix <code>repalce_qualified_name_with_use</code> assist with this diff:</p>
<div class="codehilite"><pre><span></span><code><span class="gh">diff --git a/crates/assists/src/handlers/replace_qualified_name_with_use.rs b/crates/assists/src/handlers/replace_qualified_name_with_use.rs</span>
<span class="gh">index 470e5f8ff..bcf2f164f 100644</span>
<span class="gd">--- a/crates/assists/src/handlers/replace_qualified_name_with_use.rs</span>
<span class="gi">+++ b/crates/assists/src/handlers/replace_qualified_name_with_use.rs</span>
<span class="gu">@@ -2,9 +2,14 @@ use syntax::{algo::SyntaxRewriter, ast, match_ast, AstNode, SyntaxNode, TextRang</span>
 use test_utils::mark;

 use crate::{
<span class="gd">-    utils::{find_insert_use_container, insert_use_statement},</span>
<span class="gi">+    utils::{</span>
<span class="gi">+        find_insert_use_container,</span>
<span class="gi">+        insert_use::{insert_use, MergeBehaviour},</span>
<span class="gi">+        insert_use_statement,</span>
<span class="gi">+    },</span>
     AssistContext, AssistId, AssistKind, Assists,
 };
<span class="gi">+use ast::make;</span>

 // Assist: replace_qualified_name_with_use
 //
<span class="gu">@@ -43,28 +48,25 @@ pub(crate) fn replace_qualified_name_with_use(</span>
     };

     let target = path.syntax().text_range();
<span class="gi">+    let container = find_insert_use_container(path.syntax(), ctx)?;</span>
<span class="gi">+    let syntax = container.either(|l| l.syntax().clone(), |r| r.syntax().clone());</span>
<span class="gi">+</span>
     acc.add(
         AssistId(&quot;replace_qualified_name_with_use&quot;, AssistKind::RefactorRewrite),
         &quot;Replace qualified path with use&quot;,
         target,
         |builder| {
<span class="gd">-            let container = match find_insert_use_container(path.syntax(), ctx) {</span>
<span class="gd">-                Some(c) =&gt; c,</span>
<span class="gd">-                None =&gt; return,</span>
<span class="gd">-            };</span>
<span class="gd">-            insert_use_statement(</span>
<span class="gd">-                path.syntax(),</span>
<span class="gd">-                &amp;path_to_import.to_string(),</span>
<span class="gd">-                ctx,</span>
<span class="gd">-                builder.text_edit_builder(),</span>
<span class="gd">-            );</span>
<span class="gd">-</span>
             // Now that we&#39;ve brought the name into scope, re-qualify all paths that could be
             // affected (that is, all paths inside the node we added the `use` to).
             let mut rewriter = SyntaxRewriter::default();
<span class="gd">-            let syntax = container.either(|l| l.syntax().clone(), |r| r.syntax().clone());</span>
<span class="gd">-            shorten_paths(&amp;mut rewriter, syntax, path);</span>
<span class="gd">-            builder.rewrite(rewriter);</span>
<span class="gi">+            shorten_paths(&amp;mut rewriter, syntax.clone(), path);</span>
<span class="gi">+            let new_syntax = rewriter.rewrite(&amp;syntax);</span>
<span class="gi">+            let new_syntax = insert_use(</span>
<span class="gi">+                new_syntax.clone(),</span>
<span class="gi">+                make::path_from_text(path_to_import),</span>
<span class="gi">+                Some(MergeBehaviour::Full),</span>
<span class="gi">+            );</span>
<span class="gi">+            builder.replace(syntax.text_range(), new_syntax.to_string())</span>
         },
     )
 }
</code></pre></div>



<a name="208951924"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208951924" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208951924">(Sep 03 2020 at 11:21)</a>:</h4>
<p>Some tests still fail, but this seems to mostly be because of ordering differences (<code>{foo, bar}</code> vs <code>{bar, foo}</code>).</p>



<a name="208952034"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208952034" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208952034">(Sep 03 2020 at 11:23)</a>:</h4>
<p>yes the ordering differences I changed for my tests. I'll take a look at the other stuff then again now. This should be plenty helpful thanks</p>



<a name="208952236"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208952236" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208952236">(Sep 03 2020 at 11:25)</a>:</h4>
<p>I am so exited to see this finally being worked on :-)</p>
<p>Auto-import which you need to fixup yourself is probably my No1 annoyance with rust-analyzer at the moment :0)</p>



<a name="208953057"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208953057" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208953057">(Sep 03 2020 at 11:33)</a>:</h4>
<p>good to hear, it was also one of my biggest annoyances to be honest :D. So just having it group properly will be quite nice, but also being able to configure it to not merge everything together is something I'm looking forward to cause I'm one of the people that don't like deeply nested imports <span aria-label="smiley" class="emoji emoji-1f603" role="img" title="smiley">:smiley:</span></p>



<a name="208953203"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208953203" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208953203">(Sep 03 2020 at 11:35)</a>:</h4>
<p>/me takes mental note that making features more annoying improves contributions</p>



<a name="208955453"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208955453" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208955453">(Sep 03 2020 at 11:57)</a>:</h4>
<p>Okay I managed to fix up <code>auto_import</code> and all tests pass(except one where order changed again). <code>replace_qualified_name_with_use</code> partially broke with weird invalid rust output due to nested modules, will have to check that in a bit.</p>



<a name="208955684"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208955684" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208955684">(Sep 03 2020 at 11:59)</a>:</h4>
<p>This is the output from <code>test_replace_add_use_no_anchor_in_mod_mod</code> right now</p>
<div class="codehilite"><pre><span></span><code><span class="k">mod</span> <span class="nn">foo</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="k">mod</span> <span class="nn">bar</span><span class="w"> </span><span class="k">use</span><span class="w"> </span><span class="n">std</span>::<span class="n">fmt</span>::<span class="n">Debug</span><span class="p">;</span><span class="w"></span>

<span class="p">{</span><span class="w"></span>
<span class="w">        </span><span class="n">Debug</span><span class="w"></span>
<span class="w">    </span><span class="p">}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>



<a name="208955760"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208955760" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208955760">(Sep 03 2020 at 12:00)</a>:</h4>
<p>I suppose the text range that is being replaced is not entirely correct</p>



<a name="208957917"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208957917" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208957917">(Sep 03 2020 at 12:21)</a>:</h4>
<p>Yeah, I think this needs some debugging to determine the exact semantics of <code>where_</code> / <code>position</code>.</p>
<p>In general, the problem of composing changes to syntax trees is not fully solved yet.</p>



<a name="208958307"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208958307" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208958307">(Sep 03 2020 at 12:25)</a>:</h4>
<p>I got it down to ~4 failing tests, one where it panics on an assertion in test_edit, two malformed outputs and one where it inserts imports in front of inner attributes</p>



<a name="208958655"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208958655" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208958655">(Sep 03 2020 at 12:28)</a>:</h4>
<p>The assert in <code>text_edit</code> might be interesting</p>



<a name="208958677"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208958677" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208958677">(Sep 03 2020 at 12:28)</a>:</h4>
<p>Basicallly, you build the edit by saying "replace this range with that text"</p>



<a name="208958711"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208958711" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208958711">(Sep 03 2020 at 12:28)</a>:</h4>
<p>And the assert triggers if you have overlapping ranges.</p>



<a name="208958767"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208958767" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208958767">(Sep 03 2020 at 12:29)</a>:</h4>
<p>Which is exactly the problem with composing changes.</p>



<a name="208958820"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208958820" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208958820">(Sep 03 2020 at 12:29)</a>:</h4>
<p>Oh I see, well that will be interesting to fix I guess <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="208962435"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208962435" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208962435">(Sep 03 2020 at 13:00)</a>:</h4>
<p>Ah now I see the problem with the weird malformed inner module tests. The syntax node in those cases is an <code>ItemList</code> which contains the opening and closing braces, so since there are no imports in those modules I insert them with <code>InsertPosition::First</code> causing the imports to go before the braces</p>



<a name="208962580"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208962580" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208962580">(Sep 03 2020 at 13:01)</a>:</h4>
<p>Should I special case that by checking the first token is an opening brace? That seems kinda hacky so I hope there is a better option <span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="208962817"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208962817" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208962817">(Sep 03 2020 at 13:03)</a>:</h4>
<p>I think some amount of special casing would be required</p>



<a name="208962851"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208962851" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208962851">(Sep 03 2020 at 13:03)</a>:</h4>
<p><em>Someone</em> has to figure out if we are inserting into an item list, a block (which might be supported one day) or a file.</p>



<a name="208962902"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208962902" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208962902">(Sep 03 2020 at 13:04)</a>:</h4>
<p>It's not entirely clear <em>where</em> such special casing needs to happen though.</p>



<a name="208962986"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208962986" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208962986">(Sep 03 2020 at 13:04)</a>:</h4>
<p>Maybe <code>where_</code> should have a type like</p>
<div class="codehilite"><pre><span></span><code>enum ImportScope {
    File(ast::File),
    Motule(ast::ItemList),
}
</code></pre></div>



<a name="208963382"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208963382" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208963382">(Sep 03 2020 at 13:07)</a>:</h4>
<p>Ye, that might be a good idea, I mean that is already what find_insert_use_container returns anyways + that would indeed allow easier refactoring to potentially support blocks later on I imagine. I'll check where this approach leads to</p>



<a name="208971342"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208971342" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208971342">(Sep 03 2020 at 14:02)</a>:</h4>
<p>Okay I think I fixed that problem, except that the import is now incorrectly indented.</p>



<a name="208976871"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208976871" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208976871">(Sep 03 2020 at 14:36)</a>:</h4>
<p>Alright all that's left now is the failing assert, which I'm really not sure how to fix. So as you said the problem is that the same range is being edited multiple times in the same assist "run" right? The solution I imagine is to only partial patch the text, but this is probably gonna be difficult to do given <code>insert_use</code> returns the entire edited new node.</p>



<a name="208977754"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208977754" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208977754">(Sep 03 2020 at 14:41)</a>:</h4>
<p>Uhu, but you might be able to fix around this elsewhere</p>



<a name="208977807"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208977807" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208977807">(Sep 03 2020 at 14:42)</a>:</h4>
<p>I hit exactly the same problem in the dff in the stream above</p>



<a name="208977845"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208977845" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208977845">(Sep 03 2020 at 14:42)</a>:</h4>
<p>Note how I've re-ordered <code>rewrite</code> and <code>insert_use</code></p>



<a name="208979303"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208979303" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208979303">(Sep 03 2020 at 14:52)</a>:</h4>
<p>I dont think I can do that in this case, the problem is that the test inserts imports twice, where one of the text ranges of one import contains the text range of the other modified import node</p>



<a name="208987431"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208987431" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208987431">(Sep 03 2020 at 15:46)</a>:</h4>
<p>Looking at that failure now</p>



<a name="208987466"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208987466" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208987466">(Sep 03 2020 at 15:46)</a>:</h4>
<p>IIRC, this assist panics with the old impl as well sometimes...</p>



<a name="208987831"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208987831" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208987831">(Sep 03 2020 at 15:48)</a>:</h4>
<p>(also, <code>master</code> branch has some better asserts in that area)</p>



<a name="208988872"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208988872" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208988872">(Sep 03 2020 at 15:55)</a>:</h4>
<p>Urgh, I don't see any easy way to fix this.</p>



<a name="208988919"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208988919" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208988919">(Sep 03 2020 at 15:55)</a>:</h4>
<p>I think for now I am fine with just commenting-out the <code>insert_import</code> bit in that assist</p>



<a name="208988976"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208988976" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208988976">(Sep 03 2020 at 15:55)</a>:</h4>
<p>I think a proper fix would be changing <em>other</em> things to do an AST-based edit, instad of a text-based one</p>



<a name="208989037"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208989037" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208989037">(Sep 03 2020 at 15:56)</a>:</h4>
<p>and it also interacts with that other issue about grouping "find-references" result by file</p>



<a name="208999658"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208999658" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208999658">(Sep 03 2020 at 17:08)</a>:</h4>
<p>Alright, I pushed the final commit then just now that comments out the use of that function for now</p>



<a name="208999677"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/PR%20%235935/near/208999677" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/PR.20.235935.html#208999677">(Sep 03 2020 at 17:08)</a>:</h4>
<p>Should be ready to be reviewed once more then</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>